import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

public class HashMapRewrite{
    public static void main(String[] args){
        HashMap<Key, String> hMap = new HashMap<Key, String>();
        hMap.put(new Key(1), "aaa");
        hMap.put(new Key(2), "bbb");
        hMap.put(new Key(3), "ccc");
        hMap.put(new Key(1), "ddd");
        hMap.put(new Key(1), "eee");
        hMap.put(new Key(2), "fff");
        hMap.put(new Key(3), "ggg");
        
        System.out.println("size: " + hMap.size());
        
        Iterator<Entry<Key, String>> iter = hMap.entrySet().iterator();
        while(iter.hasNext()){
            Entry<Key, String> en = iter.next();
            System.out.println(en.getKey() + " : " + en.getValue());
        }
    }
}

class Key{
    int k;
    public Key(int k){
        this.k = k;
    }
    
    public int hashCode(){
        return this.k;
    }
    
    public boolean equals(Object o){
        if(this == o){
            return true;
        }
        
        if(o.getClass() == Key.class){
            Key key = (Key)o;
            if(this.k == key.k){
                return true;
            }
        }
        
        return false;
    }

    public String toString(){
        return String.valueOf(k);
    }
}